package Demo3;

import java.util.ArrayList;

public class Solution3 {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param ss string字符串 第一个整数
     * @param tt string字符串 第二个整数
     * @return string字符串
     */
    StringBuffer ret = new StringBuffer();
    public String solve (String ss, String tt) {
        // write code here
        // write code here
        int len1 = ss.length() - 1, len2 = tt.length() - 1;
        int p = -1;
        for(int i = len1; i >= 0; i--) {
            p++;
            int tmp = 0;
            StringBuffer cur = new StringBuffer();
            for(int j = len2; j >= 0; j--) {
                int sum = ((int) (Math.pow(10 , p))) * (ss.charAt(i) - '0') * (tt.charAt(j) - '0') + tmp;
                tmp = sum / 10;
                StringBuffer stringBuffer = new StringBuffer();
                stringBuffer.append(sum % 10);
                stringBuffer.append(cur);
                cur = stringBuffer;
            }
            if(tmp != 0) {
                StringBuffer stringBuffer = new StringBuffer();
                stringBuffer.append(tmp);
                stringBuffer.append(cur);
                cur = stringBuffer;
            }
            addHead(cur);
        }
        return ret.toString();
    }
    StringBuffer tmp = null;
    private void add(Integer val) {
        if(tmp == null) {
            tmp = new StringBuffer();
            tmp.append(val);
            return;
        }
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(val);
        stringBuffer.append(tmp);
        tmp = stringBuffer;
    }
    private void addHead(StringBuffer cur) {
        // 相加
        int t = 0;
        int len1 = cur.length() - 1, len2 = ret.length() - 1;
        while(len1 >= 0 && len2 >= 0) {
            int sum = cur.charAt(len1) - '0' + ret.charAt(len2) - '0' + t;
            t = sum / 10;
            add(sum % 10);
            len1--;
            len2--;
        }
        while(len1 >= 0) {
            int sum = cur.charAt(len1) - '0' + t;
            t = sum / 10;
            add(sum % 10);
            len1--;
        }
        while(len2 >= 0) {
            int sum = ret.charAt(len2) - '0' + t;
            t = sum / 10;
            add(sum % 10);
            len2--;
        }
        if(t > 0) {
            add(t);
        }
        ret = tmp;
        tmp = null;
    }
}
class Demo5 {
    public static void main(String[] args) {
        Solution3 solution3 = new Solution3();
        String solve = solution3.solve("11", "99");
        System.out.println(solve);
    }
}
